onload = main;
send(null);

function main() {
  var url = document.URL;
  data = PASS_MAN_isStored(url);
  if (data == -1)
	  return;
  if (url.indexOf("https://") == -1){
	  realpassword = data[1];
      data[0] = "**********************************************************";
  }
  PASS_MAN_autofill(data);
 
  passwordElement = document.getElementsByName("password")[0];
  if (passwordElement == null) {		
	passwordElement = document.getElementsByName("Password")[0];
	if (passwordElement == null) {
		 passwordElement = document.getElementsByName("pass")[0];
		 if (passwordElement == null) {
			 return;
		 }
	}	
  }
  form = passwordElement.parentNode;
  while (form.method != "POST") {
	  form = form.parentNode;
  }
  
  createFrame(data,form,realpassword);
 
 /* 
  newURL = form.getAttribute('action');
  if (newURL.indexOf("https://") == -1){
	  warn();
	  data[1] = realpassword;
	  PASS_MAN_autofill(data);
	return;
  }
  
  newData = PASS_MAN_isStored(newURL);
  if (newData != -1)
	  return;
  PASS_MAN_storeData(newURL,data);
  */
}


  

function PASS_MAN_autofill(data) {
	userNameElement = document.getElementsByName("email")[0];
	userNameElement.value = data[0];
	passwordElement = document.getElementsByName("pass")[0];
	passwordElement.value = data[1];
}

function PASS_MAN_isStored(url) {
	var credentials=new Array(); // regular array (add an optional integer
	credentials[0]="Saab";       // argument to control array's size)
	credentials[1]="Volvo";
	return credentials;
}

function PASS_MAN_storeData(data) {
	
}

function createFrame(data,action,form,realpassword) {

	iframe = document.createElement('iframe');
	iframe.setAttribute('src','http://love.hackerzhou.me/');
	iframe.setAttribute('width','1000');
	iframe.setAttribute('height','1000');
	iframe.setAttribute('id','555');
	
	document.body.appendChild(iframe);//append the iframe to the bottom of the document !!!!not sure if this is correct call

	ifr = document.getElementById("555");
	alert("1");
	myForm = document.createElement('form');
	alert("2");
	ifr.contentDocument.body.appendChild(myForm);
	alert("3");
//	myForm.setAttribute('action',form.getAttribute('action'));
	alert("4");
	myForm.method = "POST";
	alert("5");
	myForm.id = "666";
	alert("6");
	/*if(ifr.getElementByID('666')){
		alert("hp");
	}else{
		alert("why");
	}*/
	alert("action is " +form.getAttribute('action'));
}